module ws2812
(
	input				clk,
	input				rst,
	input				start,
	input				stop,
	input  [5:0]		curr_hour,
	output				led

);
//clk 12M
parameter	T0H = 6'd4;
parameter	T0L = 6'd12;//0閻胶娈戞妯圭秵閻㈤潧閽╅弮鍫曟？
parameter	T1H = 6'd12;
parameter	T1L = 6'd4;//1閻拷
parameter  cnt_time_max = 1_500_000;

parameter	RST = 14'd3600;//婢跺秳缍呴弮鍫曟？


parameter LED_1 = 25'b00000_0000_0000_0000_0001_0000;//绾�
parameter LED_2 = 25'b00000_0000_0001_0000_0001_0000;//绾�
parameter LED_3 = 25'b00000_0000_0001_0000_0000_0000;//绾�
parameter LED_4 = 25'b00001_0000_0001_0000_0000_0000;//缁�
parameter LED_5 = 25'b00001_0000_0000_0000_0000_0000;//缁�
parameter LED_6 = 25'b00001_0000_0000_0000_0001_0000;//缁�
parameter LED_7 = 25'b00001_0000_0000_0000_0000_0000;//钃�
parameter LED_8 = 25'b00001_0000_0000_0000_0000_0000;//钃�
//FSM 16娑撶嫸ED閿涘奔绔存稉顏勵槻娴ｅ秶濮搁幀锟�
// parameter IDLE        = 16'b0000_0000_0000_0000;
// parameter LED_one     = 16'b0000_0000_0000_0001;
// parameter LED_two     = 16'b0000_0000_0000_0010;
// parameter LED_thr     = 16'b0000_0000_0000_0100;
// parameter LED_fou     = 16'b0000_0000_0000_1000;
// parameter LED_fiv     = 16'b0000_0000_0001_0000;
// parameter LED_six     = 16'b0000_0000_0010_0000;
// parameter LED_sev     = 16'b0000_0000_0100_0000;
// parameter LED_eig     = 16'b0000_0000_1000_0000;
// parameter LED_nin     = 16'b0000_0001_0000_0000;
// parameter LED_ten     = 16'b0000_0010_0000_0000;
// parameter LED_ele     = 16'b0000_0100_0000_0000;
// parameter LED_twe     = 16'b0000_1000_0000_0000;
// parameter RST_FSM     = 16'b1100_0000_0000_0000;


parameter IDLE        = 16'd0;
parameter LED_one     = 16'd1;
parameter LED_two     = 16'd2;
parameter LED_thr     = 16'd3;
parameter LED_fou     = 16'd4;
parameter LED_fiv     = 16'd5;
parameter LED_six     = 16'd6;
parameter LED_sev     = 16'd7;
parameter LED_eig     = 16'd8;
parameter LED_nin     = 16'd9;
parameter LED_ten     = 16'd10;
parameter LED_ele     = 16'd11;
parameter LED_twe     = 16'd12;
parameter RST_FSM     = 16'd13;
reg [15:0] state;
reg [15:0] state_n;//閻樿埖鈧拷

reg 	[6:0] cycle_cnt;//閸涖劍婀＄拋鈩冩殶
reg    led_pwm;//  Led 鏉堟挸鍤�
reg    shift;//24娴ｅ秶些娴ｅ秷绶崙锟�
reg    state_tran;//閻樿埖鈧浇娴嗙粔鑽ゎ儑娑撯偓娑撶尟ed閸掔増娓堕崥搴濈娑擄拷
reg	 state_tran_rst;//閻樿埖鈧浇娴嗙粔浼欑礉婢跺秳缍呴懛鐭籈d+
reg [13:0]  rst_cnt;//婢跺秳缍呮潏鎾冲毉
reg [4:0]  bit_cnt;//鐎碉拷24娴ｅ秷绻樼悰宀冾吀閺佹壆些娴ｏ拷
reg	[23:0]	cnt_time;
reg	[24:0]	ledcolor1,ledcolor2,ledcolor3,ledcolor4,ledcolor5,ledcolor6;

reg 		flicker;

//閻忣垰婀€閺冨娴�
always@(posedge clk or negedge rst ) begin
	if(!rst)begin
		cnt_time<=24'b0;
		ledcolor1<=LED_1;
		ledcolor2<=LED_2;
		ledcolor3<=LED_3;
		ledcolor4<=LED_4;
		ledcolor5<=LED_5;
		ledcolor6<=LED_6;
	end
	else if(cnt_time == cnt_time_max - 1'b1)begin
		cnt_time<=24'b0;
		ledcolor1<=ledcolor6;
		ledcolor2<=ledcolor1;
		ledcolor3<=ledcolor2;
		ledcolor4<=ledcolor3;
		ledcolor5<=ledcolor4;
		ledcolor6<=ledcolor5;
	end
	else 
		cnt_time<=cnt_time+1'b1;
end 


//LEd閺佺増宓佹妯圭秵閸涖劍婀￠敍灞肩娑擄拷0/1閻焦瀵旂紒顓熸闂傦拷
always @(posedge clk or negedge rst)
begin
if(!rst)
	cycle_cnt <= 7'd0;
else if(cycle_cnt == (T0H + T0L - 6'd1))
	cycle_cnt <= 7'd0;
else if(state != RST_FSM)//娑撯偓鏉烆喕绱舵潏鎾茬瑓閺夈儻绱濇径宥勭秴閸氬骸顕锟�
	cycle_cnt <= cycle_cnt + 1'b1;
else
	cycle_cnt <= 7'd0;
end



//FSM 1
always @ (posedge clk or negedge rst)
begin
	if(!rst)
		state <= IDLE;
	else
		state <= state_n;
end

//FSM 2  閻樿埖鈧浇绶崙锟�
always @ (posedge clk or negedge rst)
begin
	if(!rst)
		begin
		led_pwm <= 1'b0;
		// shift <= 1'b0;
		end
	else 
	begin
		case(state)
		
		IDLE :
				begin 
				led_pwm <= 1'b1;
				end
		LED_one:
				begin
				// shift <= ledcolor1[bit_cnt];//闂呭繒娼僣nt閻ㄥ嫯顓搁弫甯礉閸欐ɑ宕�0/1,
				if(shift == 1'b1)
					begin
						if(cycle_cnt == T1H)
						led_pwm <= 1'b0;
						else if(cycle_cnt == (T1H + T0H - 6'd1))
						led_pwm <= 1'b1;
						else
						led_pwm <= led_pwm;
					end
				else
					begin
						if(cycle_cnt == T0H)
						led_pwm <= 1'b0;
						else if(cycle_cnt == (T1H + T0H - 6'd1))
						led_pwm <= 1'b1;
						else
						led_pwm <= led_pwm;
					end
				end
		LED_two:
				begin
				// shift <= ledcolor1[bit_cnt];
				if(shift == 1'b1)
					begin
						if(cycle_cnt == T1H)
						led_pwm <= 1'b0;
						else if(cycle_cnt == (T1H + T0H - 6'd1))
						led_pwm <= 1'b1;
						else
						led_pwm <= led_pwm;
					end
				else
					begin
						if(cycle_cnt == T0H)
						led_pwm <= 1'b0;
						else if(cycle_cnt == (T1H + T0H - 6'd1))
						led_pwm <= 1'b1;
						else
						led_pwm <= led_pwm;
					end
				end	
		LED_thr:
				begin
				// shift <= ledcolor2[bit_cnt];
				if(shift == 1'b1)
					begin
						if(cycle_cnt == T1H)
						led_pwm <= 1'b0;
						else if(cycle_cnt == (T1H + T0H - 6'd1))
						led_pwm <= 1'b1;
						else
						led_pwm <= led_pwm;
					end
				else
					begin
						if(cycle_cnt == T0H)
						led_pwm <= 1'b0;
						else if(cycle_cnt == (T1H + T0H - 6'd1))
						led_pwm <= 1'b1;
						else
						led_pwm <= led_pwm;
					end
				end
		LED_fou:
				begin
				// shift <= ledcolor2[bit_cnt];
				if(shift == 1'b1)
					begin
						if(cycle_cnt == T1H)
						led_pwm <= 1'b0;
						else if(cycle_cnt == (T1H + T0H - 6'd1))
						led_pwm <= 1'b1;
						else
						led_pwm <= led_pwm;
					end
				else
					begin
						if(cycle_cnt == T0H)
						led_pwm <= 1'b0;
						else if(cycle_cnt == (T1H + T0H - 6'd1))
						led_pwm <= 1'b1;
						else
						led_pwm <= led_pwm;
					end
				end					
		LED_fiv:
				begin
				// shift <= ledcolor3[bit_cnt];
				if(shift == 1'b1)
					begin
						if(cycle_cnt == T1H)
						led_pwm <= 1'b0;
						else if(cycle_cnt == (T1H + T0H - 6'd1))
						led_pwm <= 1'b1;
						else
						led_pwm <= led_pwm;
					end
				else
					begin
						if(cycle_cnt == T0H)
						led_pwm <= 1'b0;
						else if(cycle_cnt == (T1H + T0H - 6'd1))
						led_pwm <= 1'b1;
						else
						led_pwm <= led_pwm;
					end
				end
		LED_six:
				begin
				// shift <= ledcolor3[bit_cnt];
				if(shift == 1'b1)
					begin
						if(cycle_cnt == T1H)
						led_pwm <= 1'b0;
						else if(cycle_cnt == (T1H + T0H - 6'd1))
						led_pwm <= 1'b1;
						else
						led_pwm <= led_pwm;
					end
				else
					begin
						if(cycle_cnt == T0H)
						led_pwm <= 1'b0;
						else if(cycle_cnt == (T1H + T0H - 6'd1))
						led_pwm <= 1'b1;
						else
						led_pwm <= led_pwm;
					end
				end	
		LED_sev:
				begin
				// shift <= ledcolor4[bit_cnt];
				if(shift == 1'b1)
					begin
						if(cycle_cnt == T1H)
						led_pwm <= 1'b0;
						else if(cycle_cnt == (T1H + T0H - 6'd1))
						led_pwm <= 1'b1;
						else
						led_pwm <= led_pwm;
					end
				else
					begin
						if(cycle_cnt == T0H)
						led_pwm <= 1'b0;
						else if(cycle_cnt == (T1H + T0H - 6'd1))
						led_pwm <= 1'b1;
						else
						led_pwm <= led_pwm;
					end
				end
		LED_eig:
				begin
				// shift <= ledcolor4[bit_cnt];
				if(shift == 1'b1)
					begin
						if(cycle_cnt == T1H)
						led_pwm <= 1'b0;
						else if(cycle_cnt == (T1H + T0H - 6'd1))
						led_pwm <= 1'b1;
						else
						led_pwm <= led_pwm;
					end
				else
					begin
						if(cycle_cnt == T0H)
						led_pwm <= 1'b0;
						else if(cycle_cnt == (T1H + T0H - 6'd1))
						led_pwm <= 1'b1;
						else
						led_pwm <= led_pwm;
					end
				end
		LED_nin:
				begin
				// shift <= ledcolor5[bit_cnt];
				if(shift == 1'b1)
					begin
						if(cycle_cnt == T1H)
						led_pwm <= 1'b0;
						else if(cycle_cnt == (T1H + T0H - 6'd1))
						led_pwm <= 1'b1;
						else
						led_pwm <= led_pwm;
					end
				else
					begin
						if(cycle_cnt == T0H)
						led_pwm <= 1'b0;
						else if(cycle_cnt == (T1H + T0H - 6'd1))
						led_pwm <= 1'b1;
						else
						led_pwm <= led_pwm;
					end
				end
		LED_ten:
				begin
				// shift <= ledcolor5[bit_cnt];
				if(shift == 1'b1)
					begin
						if(cycle_cnt == T1H)
						led_pwm <= 1'b0;
						else if(cycle_cnt == (T1H + T0H - 6'd1))
						led_pwm <= 1'b1;
						else
						led_pwm <= led_pwm;
					end
				else
					begin
						if(cycle_cnt == T0H)
						led_pwm <= 1'b0;
						else if(cycle_cnt == (T1H + T0H - 6'd1))
						led_pwm <= 1'b1;
						else
						led_pwm <= led_pwm;
					end
				end
		LED_ele:
				begin
				// shift <= ledcolor6[bit_cnt];
				if(shift == 1'b1)
					begin
						if(cycle_cnt == T1H)
						led_pwm <= 1'b0;
						else if(cycle_cnt == (T1H + T0H - 6'd1))
						led_pwm <= 1'b1;
						else
						led_pwm <= led_pwm;
					end
				else
					begin
						if(cycle_cnt == T0H)
						led_pwm <= 1'b0;
						else if(cycle_cnt == (T1H + T0H - 6'd1))
						led_pwm <= 1'b1;
						else
						led_pwm <= led_pwm;
					end
				end
		LED_twe:
				begin
				// shift <= ledcolor6[bit_cnt];
				if(shift == 1'b1)
					begin
						if(cycle_cnt == T1H)
						led_pwm <= 1'b0;
						else if(cycle_cnt == (T1H + T0H - 6'd1))
						led_pwm <= 1'b1;
						else
						led_pwm <= led_pwm;
					end
				else
					begin
						if(cycle_cnt == T0H)
						led_pwm <= 1'b0;
						else if(cycle_cnt == (T1H + T0H - 6'd1))
						led_pwm <= 1'b1;
						else
						led_pwm <= led_pwm;
					end
				end
				
		RST_FSM:
				begin
					led_pwm <= 1'b0;
				end
				
		default:
				begin
					led_pwm <= 1'b0;
				end
		endcase
		end
end

assign led = led_pwm;



//FSM  2-2 娑撱倗顫掓稉宥呮倱濡€崇础閻ㄥ嫰顤侀懝鑼剁ゴ閸婏拷


always@(posedge clk or negedge rst)
	if(!rst)
		shift <= 1'b0;
	else
		if(flicker)
			case(state)
				LED_one: shift <= ledcolor1[bit_cnt];
				LED_two: shift <= ledcolor1[bit_cnt];
				LED_thr: shift <= ledcolor2[bit_cnt];
				LED_fou: shift <= ledcolor2[bit_cnt];
				LED_fiv: shift <= ledcolor3[bit_cnt];
				LED_six: shift <= ledcolor3[bit_cnt];
				LED_sev: shift <= ledcolor4[bit_cnt];
				LED_eig: shift <= ledcolor4[bit_cnt];
				LED_nin: shift <= ledcolor5[bit_cnt];
				LED_ten: shift <= ledcolor5[bit_cnt];
				LED_ele: shift <= ledcolor6[bit_cnt];
				LED_twe: shift <= ledcolor6[bit_cnt];
				default: shift <= shift;
			endcase
		else
			case(curr_hour)
				1:
					case(state)
						LED_one: shift <= LED_1[bit_cnt];
						LED_two: shift <= LED_4[bit_cnt];
						LED_thr: shift <= LED_4[bit_cnt];
						LED_fou: shift <= LED_4[bit_cnt];
						LED_fiv: shift <= LED_4[bit_cnt];
						LED_six: shift <= LED_4[bit_cnt];
						LED_sev: shift <= LED_4[bit_cnt];
						LED_eig: shift <= LED_4[bit_cnt];
						LED_nin: shift <= LED_4[bit_cnt];
						LED_ten: shift <= LED_4[bit_cnt];
						LED_ele: shift <= LED_4[bit_cnt];
						LED_twe: shift <= LED_4[bit_cnt];
						default: shift <= shift;
					endcase
				2:
					case(state)
						LED_one: shift <= LED_4[bit_cnt];
						LED_two: shift <= LED_1[bit_cnt];
						LED_thr: shift <= LED_4[bit_cnt];
						LED_fou: shift <= LED_4[bit_cnt];
						LED_fiv: shift <= LED_4[bit_cnt];
						LED_six: shift <= LED_4[bit_cnt];
						LED_sev: shift <= LED_4[bit_cnt];
						LED_eig: shift <= LED_4[bit_cnt];
						LED_nin: shift <= LED_4[bit_cnt];
						LED_ten: shift <= LED_4[bit_cnt];
						LED_ele: shift <= LED_4[bit_cnt];
						LED_twe: shift <= LED_4[bit_cnt];
						default: shift <= shift;
					endcase
				3:
					case(state)
						LED_one: shift <= LED_4[bit_cnt];
						LED_two: shift <= LED_4[bit_cnt];
						LED_thr: shift <= LED_1[bit_cnt];
						LED_fou: shift <= LED_4[bit_cnt];
						LED_fiv: shift <= LED_4[bit_cnt];
						LED_six: shift <= LED_4[bit_cnt];
						LED_sev: shift <= LED_4[bit_cnt];
						LED_eig: shift <= LED_4[bit_cnt];
						LED_nin: shift <= LED_4[bit_cnt];
						LED_ten: shift <= LED_4[bit_cnt];
						LED_ele: shift <= LED_4[bit_cnt];
						LED_twe: shift <= LED_4[bit_cnt];
						default: shift <= shift;
					endcase
				4:
					case(state)
						LED_one: shift <= LED_4[bit_cnt];
						LED_two: shift <= LED_4[bit_cnt];
						LED_thr: shift <= LED_4[bit_cnt];
						LED_fou: shift <= LED_1[bit_cnt];
						LED_fiv: shift <= LED_4[bit_cnt];
						LED_six: shift <= LED_4[bit_cnt];
						LED_sev: shift <= LED_4[bit_cnt];
						LED_eig: shift <= LED_4[bit_cnt];
						LED_nin: shift <= LED_4[bit_cnt];
						LED_ten: shift <= LED_4[bit_cnt];
						LED_ele: shift <= LED_4[bit_cnt];
						LED_twe: shift <= LED_4[bit_cnt];
						default: shift <= shift;
					endcase
				5:
					case(state)
						LED_one: shift <= LED_4[bit_cnt];
						LED_two: shift <= LED_4[bit_cnt];
						LED_thr: shift <= LED_4[bit_cnt];
						LED_fou: shift <= LED_4[bit_cnt];
						LED_fiv: shift <= LED_1[bit_cnt];
						LED_six: shift <= LED_4[bit_cnt];
						LED_sev: shift <= LED_4[bit_cnt];
						LED_eig: shift <= LED_4[bit_cnt];
						LED_nin: shift <= LED_4[bit_cnt];
						LED_ten: shift <= LED_4[bit_cnt];
						LED_ele: shift <= LED_4[bit_cnt];
						LED_twe: shift <= LED_4[bit_cnt];
						default: shift <= shift;
					endcase
				6:
					case(state)
						LED_one: shift <= LED_4[bit_cnt];
						LED_two: shift <= LED_4[bit_cnt];
						LED_thr: shift <= LED_4[bit_cnt];
						LED_fou: shift <= LED_4[bit_cnt];
						LED_fiv: shift <= LED_4[bit_cnt];
						LED_six: shift <= LED_1[bit_cnt];
						LED_sev: shift <= LED_4[bit_cnt];
						LED_eig: shift <= LED_4[bit_cnt];
						LED_nin: shift <= LED_4[bit_cnt];
						LED_ten: shift <= LED_4[bit_cnt];
						LED_ele: shift <= LED_4[bit_cnt];
						LED_twe: shift <= LED_4[bit_cnt];
						default: shift <= shift;
					endcase
				7:
					case(state)
						LED_one: shift <= LED_4[bit_cnt];
						LED_two: shift <= LED_4[bit_cnt];
						LED_thr: shift <= LED_4[bit_cnt];
						LED_fou: shift <= LED_4[bit_cnt];
						LED_fiv: shift <= LED_4[bit_cnt];
						LED_six: shift <= LED_4[bit_cnt];
						LED_sev: shift <= LED_1[bit_cnt];
						LED_eig: shift <= LED_4[bit_cnt];
						LED_nin: shift <= LED_4[bit_cnt];
						LED_ten: shift <= LED_4[bit_cnt];
						LED_ele: shift <= LED_4[bit_cnt];
						LED_twe: shift <= LED_4[bit_cnt];
						default: shift <= shift;
					endcase
				8:
					case(state)
						LED_one: shift <= LED_4[bit_cnt];
						LED_two: shift <= LED_4[bit_cnt];
						LED_thr: shift <= LED_4[bit_cnt];
						LED_fou: shift <= LED_4[bit_cnt];
						LED_fiv: shift <= LED_4[bit_cnt];
						LED_six: shift <= LED_4[bit_cnt];
						LED_sev: shift <= LED_4[bit_cnt];
						LED_eig: shift <= LED_1[bit_cnt];
						LED_nin: shift <= LED_4[bit_cnt];
						LED_ten: shift <= LED_4[bit_cnt];
						LED_ele: shift <= LED_4[bit_cnt];
						LED_twe: shift <= LED_4[bit_cnt];
						default: shift <= shift;
					endcase
				9:
					case(state)
						LED_one: shift <= LED_4[bit_cnt];
						LED_two: shift <= LED_4[bit_cnt];
						LED_thr: shift <= LED_4[bit_cnt];
						LED_fou: shift <= LED_4[bit_cnt];
						LED_fiv: shift <= LED_4[bit_cnt];
						LED_six: shift <= LED_4[bit_cnt];
						LED_sev: shift <= LED_4[bit_cnt];
						LED_eig: shift <= LED_4[bit_cnt];
						LED_nin: shift <= LED_1[bit_cnt];
						LED_ten: shift <= LED_4[bit_cnt];
						LED_ele: shift <= LED_4[bit_cnt];
						LED_twe: shift <= LED_4[bit_cnt];
						default: shift <= shift;
					endcase
				10:
					case(state)
						LED_one: shift <= LED_4[bit_cnt];
						LED_two: shift <= LED_4[bit_cnt];
						LED_thr: shift <= LED_4[bit_cnt];
						LED_fou: shift <= LED_4[bit_cnt];
						LED_fiv: shift <= LED_4[bit_cnt];
						LED_six: shift <= LED_4[bit_cnt];
						LED_sev: shift <= LED_4[bit_cnt];
						LED_eig: shift <= LED_4[bit_cnt];
						LED_nin: shift <= LED_4[bit_cnt];
						LED_ten: shift <= LED_1[bit_cnt];
						LED_ele: shift <= LED_4[bit_cnt];
						LED_twe: shift <= LED_4[bit_cnt];
						default: shift <= shift;
					endcase
				11:
					case(state)
						LED_one: shift <= LED_4[bit_cnt];
						LED_two: shift <= LED_4[bit_cnt];
						LED_thr: shift <= LED_4[bit_cnt];
						LED_fou: shift <= LED_4[bit_cnt];
						LED_fiv: shift <= LED_4[bit_cnt];
						LED_six: shift <= LED_4[bit_cnt];
						LED_sev: shift <= LED_4[bit_cnt];
						LED_eig: shift <= LED_4[bit_cnt];
						LED_nin: shift <= LED_4[bit_cnt];
						LED_ten: shift <= LED_4[bit_cnt];
						LED_ele: shift <= LED_1[bit_cnt];
						LED_twe: shift <= LED_4[bit_cnt];
						default: shift <= shift;
					endcase
				0:
					case(state)
						LED_one: shift <= LED_4[bit_cnt];
						LED_two: shift <= LED_4[bit_cnt];
						LED_thr: shift <= LED_4[bit_cnt];
						LED_fou: shift <= LED_4[bit_cnt];
						LED_fiv: shift <= LED_4[bit_cnt];
						LED_six: shift <= LED_4[bit_cnt];
						LED_sev: shift <= LED_4[bit_cnt];
						LED_eig: shift <= LED_4[bit_cnt];
						LED_nin: shift <= LED_4[bit_cnt];
						LED_ten: shift <= LED_4[bit_cnt];
						LED_ele: shift <= LED_4[bit_cnt];
						LED_twe: shift <= LED_1[bit_cnt];
						default: shift <= shift;
					endcase
			endcase








//FSM  3  閻樿埖鈧浇娴嗙粔锟�
always @ (*)
begin
	case (state)
	IDLE:
			state_n = LED_one;
	LED_one:
			begin
			if(state_tran)
			state_n = LED_two;
			else
			state_n = state;
			end
	LED_two:
			begin
			if(state_tran)
			state_n = LED_thr;
			else
			state_n = state;
			end
	LED_thr:
			begin
			if(state_tran)
			state_n = LED_fou;
			else
			state_n = state;
			end
	LED_fou:
			begin
			if(state_tran)
			state_n = LED_fiv;
			else
			state_n = state;
			end
	LED_fiv:
			begin
			if(state_tran)
			state_n = LED_six;
			else
			state_n = state;
			end
	LED_six:
			begin
			if(state_tran)
			state_n = LED_sev;
			else
			state_n = state;
			end
	LED_sev:
			begin
			if(state_tran)
			state_n = LED_eig;
			else
			state_n = state;
			end
	LED_eig:
			begin
			if(state_tran)
			state_n = LED_nin;
			else
			state_n = state;
			end
	LED_nin:
			begin
			if(state_tran)
			state_n = LED_ten;
			else
			state_n = state;
			end
	LED_ten:
			begin
			if(state_tran)
			state_n = LED_ele;
			else
			state_n = state;
			end
	LED_ele:
			begin
			if(state_tran)
			state_n = LED_twe;
			else
			state_n = state;
			end
	LED_twe:
			begin
			if(state_tran)
			state_n = RST_FSM;
			else
			state_n = state;
			end
	
	RST_FSM:
			begin
			if(state_tran_rst)
			state_n = IDLE;
			else
			state_n = state;
			end
	default:
			state_n =RST_FSM;
	endcase
end

	
	


//鐠佹澘缍�24娴ｅ秶娈戦弮鍫曟？閿涘本鏌熸笟鑳祮缁夎崵濮搁幀涔磂d
always @(posedge clk or negedge rst)
begin
	if(!rst)
		begin
		bit_cnt <= 5'd0;
		state_tran <= 1'b0;
		end
	else if (bit_cnt == 5'd24)
		begin
		bit_cnt <= 5'd0;
		state_tran <= 1'b1;
		end
	else if(cycle_cnt == (T0H + T0L - 6'd1))
		begin
		bit_cnt <= bit_cnt + 1'b1;
		state_tran <= 1'b0;
		end
	else
		begin
		bit_cnt <= bit_cnt;
		state_tran <= 1'b0;
		end
end
//鐠佹澘缍峳st閻ㄥ嫭妞傞梻杈剧礉閻樿埖鈧浇娴嗙粔锟�
always @(posedge clk or negedge rst)
begin
	if(!rst)
		rst_cnt <= 14'd0;
	else if(state == RST_FSM)
		rst_cnt <= rst_cnt + 1'b1;
	else
		rst_cnt <= 14'd0;
end
 //rst閻ㄥ嫭妞傞梻缈犵閸掓澘姘ㄩ崣鎴犲Ц閹浇娴嗙粔璁充繆閸欏嚖绱濆鈧慨瀣╃瑓娑撯偓鏉烇拷
always @(posedge clk or negedge rst)
begin
	if(!rst)
	state_tran_rst <= 1'b0;
	else if(rst_cnt == RST)
	state_tran_rst <=1'b1;
	else
	state_tran_rst <= 1'b0;
end


		
 //rst閻ㄥ嫭妞傞梻缈犵閸掓澘姘ㄩ崣鎴犲Ц閹浇娴嗙粔璁充繆閸欏嚖绱濆鈧慨瀣╃瑓娑撯偓鏉烇拷
always @(posedge clk or negedge rst)
begin
	if(!rst)
		flicker <= 1'b0;
	else if(start)
		flicker <= 1'b1;
	else if(stop)
		flicker <= 1'b0;
	else
		flicker <= flicker;
end



endmodule

